$(function() {
	$('#btnClick').click(function() {
		var val = [];
		$(':checkbox:checked').each(function(i) {
			val[i] = $(this).val();
			deleteAjax(val[i]);
		});
	});
});

function delImg(key1,key2) {
	
	var url = "deleteimg.action";
	$.ajax({
				url : url,
				data : {
					topicImageId: key1,
					topicId : key2
				},
				success : function(data) {
					$('#imagechange').html('');
					var i = 0;
					for(i=0;i<data.lstimages.length;i++){
						$('#imagechange').append("<a href=\"#\" onclick=\"delImg("+data.lstimages[i][0]+","+data.lstimages[i][1]+");\"><img src=\"Img/Topic/"+data.lstimages[i][2]+"\" width=\"35\" height=\"35\" /></a>");
					}
					
					
					
				}
			});
}

function deleteAjax(key) {
	var url = "deletefav.action";
	$
			.ajax({
				url : url,
				data : {
					topicId : key
				},
				success : function(data) {
					var i = 0;
					$('#favtopic').html('');
					for (i = 0; i < data.ownerFavorite.length; i++) {
						if (data.ownerFavorite[i][11] == 2) {
							$('#favtopic')
									.append(
											"<div class=\"contentinfo\">"
													+ "<div class=\"checkbox\">"
													+ "<input type=\"checkbox\" class=\"case\" name=\"localtion\""
													+ "value=\""
													+ data.ownerFavorite[i][9]
													+ "\">"
													+ "</div>"
													+ "<div class=\"smallimg\">"
													+ "<div class=\"smallimgview\">"
													+ "<img src=\"Img/Topic/"
													+ data.ownerFavorite[i][8]
													+ "\" width=\"88\" height=\"58\" alt=\"\">"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"contentinfomain\">"
													+ "<div class=\"title_content\">"
													+ "<a href=\"detail.action?topicId="
													+ data.ownerFavorite[i][9]
													+ "&districtId="
													+ data.ownerFavorite[i][11]
													+ "\""
													+ "class=\"atitle\">"
													+ data.ownerFavorite[i][0]
													+ " </a>"
													+ "</div>"
													+ "<div class=\"address_content\">"
													+ ""
													+ data.ownerFavorite[i][1]
													+ ""
													+ "</div>"
													+ "<div class=\"address_content\">"
													+ "<div class=\"splitcontent1\">"
													+ "Giá:<span style=\"color: #FF4500\">"
													+ data.ownerFavorite[i][2]
													+ " triệu/tháng</span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Diện tích: <span style=\"color: #FF4500\">"
													+ data.ownerFavorite[i][3]
													+ " m2</span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Lượt xem: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][4]
													+ " </span>"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"address_content\">"
													+

													"<div class=\"splitcontent1\" style=\"width: 60%\">"
													+ "Ngày tạo: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][5]
													+ " </span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Tạo bởi: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][13]
													+ " </span>"
													+ "</div>"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"boxleftcontent\" id=\"price_content\""
													+ "style=\"background: #F0F8FF\">"
													+ "<div class=\"splitrightc1\">"
													+ "<a href=\"\" style=\"color: #00C\">"
													+ data.ownerFavorite[i][14]
													+ " </a>"
													+ "</div>"
													+ "<div class=\"splitrightc1\"></div>"
													+ "<div class=\"splitrightc1\">"
													+ "<a href=\"\" style=\"color: #32CD32\">Chia sẻ</a>"
													+ "</div>" +

													"</div>" + "</div>");
						} else {
							$('#favtopic')
									.append(
											"<div class=\"contentinfo\">"
													+ "<div class=\"checkbox\">"
													+ "<input type=\"checkbox\" class=\"case\" name=\"localtion\""
													+ "value=\""
													+ data.ownerFavorite[i][9]
													+ "\">"
													+ "</div>"
													+ "<div class=\"smallimg\">"
													+ "<div class=\"smallimgview\">"
													+ "<img src=\"Img/Topic/"
													+ data.ownerFavorite[i][8]
													+ "\" width=\"88\" height=\"58\" alt=\"\">"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"contentinfomain\">"
													+ "<div class=\"title_content\">"
													+ "<a href=\"detail.action?topicId="
													+ data.ownerFavorite[i][9]
													+ "&districtId="
													+ data.ownerFavorite[i][11]
													+ "\""
													+ "class=\"atitle\">"
													+ data.ownerFavorite[i][0]
													+ " </a>"
													+ "</div>"
													+ "<div class=\"address_content\">"
													+ ""
													+ data.ownerFavorite[i][1]
													+ ""
													+ "</div>"
													+ "<div class=\"address_content\">"
													+ "<div class=\"splitcontent1\">"
													+ "Giá:<span style=\"color: #FF4500\">"
													+ data.ownerFavorite[i][2]
													+ " triệu/tháng</span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Diện tích: <span style=\"color: #FF4500\">"
													+ data.ownerFavorite[i][3]
													+ " m2</span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Lượt xem: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][4]
													+ " </span>"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"address_content\">"
													+

													"<div class=\"splitcontent1\" style=\"width: 60%\">"
													+ "Ngày tạo: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][5]
													+ " </span>"
													+ "</div>"
													+ "<div class=\"splitcontent1\">"
													+ "Tạo bởi: <span style=\"color: #1E90FF\">"
													+ data.ownerFavorite[i][13]
													+ " </span>"
													+ "</div>"
													+ "</div>"
													+ "</div>"
													+ "<div class=\"boxleftcontent\" id=\"price_content\""
													+ "style=\"background: #F0F8FF\">"
													+ "<div class=\"splitrightc1\">"
													+ "<a href=\"\" style=\"color: #00C\">"
													+ data.ownerFavorite[i][14]
													+ " </a>"
													+ "</div>"
													+ "<div class=\"splitrightc1\"></div>"
													+ "<div class=\"splitrightc1\">"
													+ "<a href=\"\" style=\"color: #FF0000\">Cho thuê</a>"
													+ "</div>" +

													"</div>" + "</div>");
						}

					}

				}
			});
}